#!/usr/bin/env bash

#get this script real directory
SOURCE="$0"
while [ -h "$SOURCE"  ]; do # resolve $SOURCE until the file is no longer a symlink
    this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"
    SOURCE="$(readlink "$SOURCE")"
    # if $SOURCE was a relative symlink, 
    #we need to resolve it relative to the path 
    #where the symlink file was located
    [[ $SOURCE != /*  ]] && SOURCE="$this_script_dir/$SOURCE"
done
this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"

log_level=${log_level:=info}
assist_dir=${assist_dir:=${this_script_dir}/assist}
source $assist_dir/global.sh

################################################################################
#                                                                          80col
print_help()
{
    cat <<EOF
    useage:
      install criu by compile: $0 --interval=5

    --interval=n  - loop output by interval n seconds, default is 5

    --log_level=<debug> - control pint log on streen,trace|debug|info|warn|error|critical

    --help  - prints help screen, script will exit after printing


EOF
}

main()
{
    if [ $_arg_num_ -eq 0 ] || [ -n "$help" ] ; then
        print_help
        return 0;
    fi

    if [ -n "$interval" ] ; then
        local count=0;
        [ "$interval" == "interval" ] && interval=5
        while true ;
        do
            let count=count+1
            vlogi "timer interver $interval seconds, count is $count"
            sleep $interval
            if [ $count -ge 1000 ] ; then break; fi
        done
    elif [ -n "$criu" ] ; then
        install_criu $criu
    fi

    return 0
}
main || exit 1 && exit 0



